package com.example.common.api;

import lombok.Data;

@Data
public class ApiResult<T> {
    
    private Integer code;
    
    private String message;
    
    private T data;
    
    private ApiResult() {}
    
    private ApiResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    
    public static <T> ApiResult<T> success() {
        return new ApiResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null);
    }
    
    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }
    
    public static <T> ApiResult<T> success(String message, T data) {
        return new ApiResult<>(ResultCode.SUCCESS.getCode(), message, data);
    }
    
    public static <T> ApiResult<T> failed() {
        return new ApiResult<>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(), null);
    }
    
    public static <T> ApiResult<T> failed(String message) {
        return new ApiResult<>(ResultCode.FAILED.getCode(), message, null);
    }
    
    public static <T> ApiResult<T> failed(IResultCode resultCode) {
        return new ApiResult<>(resultCode.getCode(), resultCode.getMessage(), null);
    }
    
    public static <T> ApiResult<T> failed(IResultCode resultCode, String message) {
        return new ApiResult<>(resultCode.getCode(), message, null);
    }
    
    public static <T> ApiResult<T> validateFailed() {
        return new ApiResult<>(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMessage(), null);
    }
    
    public static <T> ApiResult<T> validateFailed(String message) {
        return new ApiResult<>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
    }
} 